package com.lwq.reposity.impl;

import com.lwq.entity.Student;
import com.lwq.reposity.StudentRepository;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName
 * @Description
 * @Author liwq
 * @Date 2021/1/31 0:03
 * @Version 1.0
 */
@Repository
public class StudentRepositoryImpl implements StudentRepository {
    private static Map<Long, Student> studentMap;

    static {
        studentMap = new HashMap<>();
        studentMap.put(1L, new Student(1L, "张三", 11));
        studentMap.put(2L, new Student(1L, "李四", 11));
        studentMap.put(3L, new Student(1L, "王五", 11));
    }

    @Override
    public Collection<Student> findAll() {
        String dd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
        System.out.println(dd);
        return studentMap.values();
    }

    @Override
    public Student findById(long id) {
        return studentMap.get(id);
    }

    @Override
    public void saveOrUpdate(Student s) {
        studentMap.put(s.getId(), s);
    }

    @Override
    public void deleteById(long id) {
        studentMap.remove(id);
    }
}
